package com.michaelbulava.TFS.ui.framework.wizard;

import com.intellij.ide.wizard.CommitStepException;
import com.intellij.ide.wizard.Step;
import com.intellij.ide.wizard.StepListener;
import com.intellij.openapi.Disposable;
import com.intellij.util.EventDispatcher;

import javax.swing.*;

/**
 * Created by mbulava on 6/19/2015.
 */
public abstract class ExtendedWizardStep implements Step, Disposable {

    public interface Listener extends StepListener {
        void doNextAction();
    }

    protected static enum CommitType {
        Prev,
        Next,
        Finish;

        private CommitType() {
        }
    }

    private String myTitle;
    private final EventDispatcher<Listener> myEventDispatcher = EventDispatcher.create(Listener.class);

    public ExtendedWizardStep(String title){
        this.myTitle = title;
    }

    @Override
    public void _init() {
    }

    @Override
    public void _commit(boolean finish) throws CommitStepException {
        commit(finish ? CommitType.Finish : CommitType.Next);
    }

    @Override
    public Icon getIcon() {
        return null;
    }

    @Override
    public void dispose() {}

    public String getHelpId(){
        return null;
    }




    protected void fireStateChanged(){
        myEventDispatcher.getMulticaster().stateChanged();
    }

    protected void fireGoNext(){
        myEventDispatcher.getMulticaster().doNextAction();
    }

    public String getTitle(){
        return myTitle;
    }

    public void setTitle(String title){
        this.myTitle = title;
    }

    public final void _commitPrev() throws CommitStepException{
        this.commit(CommitType.Prev);
    }

    public void addStepListener(Listener listener){
        myEventDispatcher.addListener(listener);
    }




    public abstract Object getStepId();

    public abstract Object getNextStepId();

    public abstract Object getPreviousStepId();

    public abstract void commit(CommitType commitType) throws CommitStepException;

    public abstract boolean isComplete();

}
